package com.imooc.pay.config.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.beans.PropertyVetoException;

@Configuration
public class DataSourceConfig {

    @Value("${jdbc.driver}")
    private String driver;

    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.username}")
    private String username;

    @Value("${jdbc.password}")
    private String password;

    @Bean(name = "datasource")
    public ComboPooledDataSource dataSourcePool() throws PropertyVetoException {
        ComboPooledDataSource pool = new ComboPooledDataSource();
        pool.setDriverClass(driver);
        pool.setJdbcUrl(url);
        pool.setUser(username);
        pool.setPassword(password);
        pool.setMinPoolSize(40);
        pool.setMinPoolSize(10);
        pool.setAutoCommitOnClose(false);
        pool.setCheckoutTimeout(10000);
        pool.setAcquireRetryAttempts(2);
        return pool;
    }

}
